package com.sakura.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Sakura
 * @Date 2022-11-19 17:37
 */
@Configuration
@EnableSwagger2
public class SwaggerAutoConfiguration {

    //构建 api文档的详细信息
    private ApiInfo apiInfoSelf(){
        return new ApiInfoBuilder()
                //页面标题
                .title("api接口文档")
                //创建人
                .contact(new Contact("sakura","www.sakura.com","123@qq.com"))
                //版本号
                .version("1.0")
                //描述
                .description("Api 描述")
                .build();
    }

    @Bean
    public Docket createApiUser(){

        //Docket用于封装相关接口文档信息
        Docket docket =new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoSelf()).groupName("用户接口组")
                .select()
                //当前包路径
                .apis(RequestHandlerSelectors.basePackage("com.sakura.controller.user"))
                .build();
        return docket;
    }

    @Bean
    public Docket createApiMenu(){

        //Docket用于封装相关接口文档信息
        Docket docket =new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoSelf()).groupName("菜单接口组")
                .select()
                //当前包路径
                .apis(RequestHandlerSelectors.basePackage("com.sakura.controller.menu"))
                .build();
        return docket;
    }

}
